package exam.xiaomi.S2;

/**
 * @Author: 18362
 * @Create: 2022-09-14 19:02:01 星期三
 */
class Solution {

    private Node head = null;
    private Node pre = null;

    /* Write Code Here */
    public Node Convert(Node pRootOfTree) {
        if (pRootOfTree == null)
            return null;
        inorder(pRootOfTree);
        return head;
    }

    private void inorder(Node root) {
        if (root.left != null)
            inorder(root.left);
        if (root.left == null && root.right == null && head == null) {
            head = root;
            pre = root;
            return;
        }
        pre.right = root;
        root.left = pre;
        pre = root;
        if (root.right != null)
            inorder(root.right);
    }
}